<template>
  <div class="student-body">
        <h2 class="box_tit">
            <i class="icon icon1"></i>调查问卷管理
            <i class="reti"></i>
        </h2>
        <!-- <div class="blank20"></div> -->
        <el-form :inline="true" :model="queryFormData" class="demo-form-inline" ref="from" @keyup.enter.native="onSubmit">
            <el-form-item label="问卷名称：" prop="questionnaireName">
                <el-input v-model="queryFormData.questionnaireName" placeholder="请输入问卷名称" clearable></el-input>
            </el-form-item>
            <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="onSubmit">查询</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-refresh" size="mini" @click="resertSearch">重置</el-button>
                </el-form-item>
        </el-form>
            <div class="components_btns clearfix">
              <a href="javascript:void(0);" v-has="'questionnaire:add'" class="btns add"  @click="showAddQuestionnaireDialog()">添加调查问卷</a>
            </div>
        <div class="">
                <vue-table
                      :api-url="questionnaireTable.apiUrl"
                      :fields="questionnaireTable.fields"
                      :appendParams="queryFormData"
                      :content="self"
                      ref="questionnaireTable">
                </vue-table>
        </div>
        <questionnaire-add ref="questionnaireAdd"></questionnaire-add>
        <questionnaire-edit ref="questionnaireEdit"></questionnaire-edit>
  </div>
</template>
<script>
    import {enums} from '@/constant'
    import moment from 'moment'
    import questionnaire_add from './questionnaire-add'
    import questionnaire_edit from './questionnaire-edit'
    export default{
      components:{
        "questionnaire-add":questionnaire_add,
        "questionnaire-edit":questionnaire_edit
      },
        data(){
            return {
                self:this,
                queryFormData:{
                  questionnaireName:null
                },
                questionnaireTable: {
                    apiUrl: api.questionnaire.queryQuestionnaire,
                    fields: [
                        {
                            prop: "questionnaireName",
                            label: "调查问卷名称"
                        },
                        {
                            prop: "remark",
                            label: "备注",
                        },
                        {
                            prop: "__action",
                            label: "操作",
                            width:"250",
                            actions: [{
                                    label: "编辑",
                                    type: "edit",
                                    auth: 'questionnaire:modify',
                                    func: function(vm, row) {
                                        vm.$refs.questionnaireEdit.showDialog(row.id);
                                    }
                                },
                                {
                                    label: "删除",
                                    type: "edit",
                                    auth: 'questionnaire:delete',
                                    func: function(vm, row) {
                                       vm.deleteById(row.id);
                                    }
                                },
                                {
                                    label: "管理",
                                    type: "edit",
                                    auth: 'questionnaireItem:view',
                                    func: function(vm, row) {
                                       vm.$router.push('/jw/questionnaire/list/'+row.id);
                                    }
                                },
                            ]
                        },
                    ],
                },
            }
        },
        created(){
        },
        methods:{
            showAddQuestionnaireDialog(){
                this.$refs.questionnaireAdd.showDialog();
            },
            onSubmit(){
                this.$refs.questionnaireTable.$emit('vuetable:refresh')
            },
            deleteById(id){
              let self = this;
              self.$confirm('是否删除该条记录！', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.axios.delete(api.questionnaire.delete+id)
                        .then((response) => {
                            if (response.data.success) {
                                self.$message({
                                    type: 'success',
                                    message: response.data.msg,
                                });
                                self.$refs.questionnaireTable.$emit('vuetable:current-refresh');
                            } else {
                                self.$message.error(response.data.msg);
                            }
                        })
                }, () => {});

            },
            resertSearch(){
              let self = this;
              if(this.$refs['from']!==undefined){
                    this.$refs['from'].resetFields();
                }
              this.$refs.questionnaireTable.$emit('vuetable:refresh')
            },
        }
    }


</script>
<style scoped>
.student-body {
  min-height: 545px;
  width: 100%;
  background: #fff;
  border-radius: 4px;
  padding: 15px;
}
.student-body .contents span {
  display: inline-block;
  width: 100px;
  margin-top: 10px;
  text-align: right;
}
.student-body .contents .spanInput {
  height: 26px;
  width: 206px;
  line-height: 26px;
  font-size: 12px;
  color: #cdcdcd;
  text-indent: 5px;
  border-radius: 15px;
  border: 1px solid #cdcdcd;
  box-sizing: border-box;
  outline: none;
}

.student-body .contents .sexSpan {
  width: 20px;
  padding-left: 20px;
}
.student-body .contents .sexSpans{
  width: 50px;
}
.student-body .contents .lableInput {
  position: absolute;
  top: 12px;
  left: 105px;
}
.student-body .contents
.student-body .reti {
  width: 94px;
}
.student-body .inputs {
  width: 100%;
  height: 40px;
  padding-top: 20px;
}
.student-body .inputs > span {
  font-size: 12px;
  color: #333;
  padding-left: 1px;
}

.box_tit {
  border-bottom: 1px solid #e6e8ec;
  position: relative;
  padding: 4px 0 10px 30px;
  margin-top: 0;
  font-weight: bold;
  line-height: 16px;
}
</style>

